<!-- 获取验证字段 -->
<template>
  <GlobalWindow
    :title="title"
    :visible.sync="visible"
    :confirm-working="isWorking"
    width="36%"
    @confirm="confirm"
  >
    <el-form :model="form" ref="form" :rules="rules">
      <el-form-item label="图标名称" prop="name" required>
        <el-input
          v-model="form.name"
          placeholder="请输入图标名称"
          v-trim
        />
      </el-form-item>
      <el-form-item label="图标类型" prop="accessType" required>
        <DictSelect
          v-model="form.accessType"
          code="ICON_TYPES"
          placeholder="请选择图标类型"
          :clearable="true"
        />
      </el-form-item>
      <el-form-item
        v-if="form.accessType === 'CLASS'"
        label="图标CLASS"
        prop="className"
        required
      >
        <el-input
          v-model="form.className"
          placeholder="请输入图标CLASS"
          v-trim
        />
      </el-form-item>
      <el-form-item
        v-else-if="form.accessType === 'URI'"
        label="网络路径"
        prop="uri"
        required
      >
        <el-input
          v-model="form.uri"
          placeholder="请输入网络路径"
          v-trim
        />
      </el-form-item>
      <el-form-item label="预览">
        <Icon :data="form" size="22px"/>
      </el-form-item>
    </el-form>
  </GlobalWindow>
</template>

<script>
import BaseOpera from '@/components/base/BaseOpera.vue'
import { checkUrl } from '@/core/utils/form'

export default {
  name: 'OperaIconWindow',
  extends: BaseOpera,
  data () {
    return {
      // 表单数据
      form: {
        id: null,
        name: '',
        accessType: 'CLASS',
        className: 'iconfont ',
        uri: ''
      },
      // 验证规则
      rules: {
        name: [
          { required: true, message: '请输入图标名称' }
        ],
        accessType: [
          { required: true, message: '请选择图标类型' }
        ],
        className: [
          { required: true, message: '请输入图标CLASS' }
        ],
        uri: [
          { required: true, message: '请选择图标类型' },
          { validator: checkUrl, message: '网络路径不正确' }
        ]
      }
    }
  },
  created () {
    this.config({
      api: '/system/icon',
      'field.id': 'id'
    })
  }
}
</script>
